package cn.edu.zjicm.wordsnet_d.view;

import android.app.Dialog;
import android.content.Context;
import android.view.Display;
import android.view.Gravity;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;

/**
 * 为了解决圆角dialog问题
 * 
 * @author cnting
 * 
 */
public class MyDialog extends Dialog {

	private static int default_width = 160; // 默认宽度
	private static int default_height = 120; // 默认高度

	public MyDialog(Context context, View layout, int style, boolean narrow) {
		this(context, default_width, default_height, layout, style, narrow);
	}

	public MyDialog(Context context, int width, int height, View layout, int style, boolean narrow) {
		super(context, style);
		setContentView(layout);
		Window window = getWindow();
		Display display = window.getWindowManager().getDefaultDisplay();
		WindowManager.LayoutParams params = window.getAttributes();
		if (narrow) {
			params.width = (int) (display.getWidth() * 0.80);
		} else {
			params.width = (int) (display.getWidth() * 0.85);
		}

		params.height = WindowManager.LayoutParams.WRAP_CONTENT;
		// params.horizontalMargin = 0.1f;
		// params.verticalMargin = 0.1f;
		params.gravity = Gravity.CENTER;
		window.setAttributes(params);

		setCanceledOnTouchOutside(false); // 设置为点击对话框外屏幕，Dialog不消失
	}
}
